package com.yeyks.controller.finance;

import com.google.common.collect.Lists;
import com.yeyks.account.dal.domain.AccountInfo;
import com.yeyks.annotation.NeedToken;
import com.yeyks.common.ajax.AjaxResponseBody;
import com.yeyks.common.base.Arguments;
import com.yeyks.common.base.PageResult;
import com.yeyks.common.param.WithdrawalOrderParam;
import com.yeyks.common.param.finance.FinanceWithdrawalParam;
import com.yeyks.common.result.withdrawalorder.HotelWithdrawalOrderResult;
import com.yeyks.commonReference.service.hotel.HotelWithdrawalOrderService;
import com.yeyks.hotel.dal.domain.HotelWithdrawalOrder;
import com.yeyks.web.AccountUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 财务小vip酒店财务模块接口
 *
 * @author shuai
 * @date 2019-07-09
 */
@Slf4j
@Api(tags = "财务小vip酒店财务模块接口")
@RestController
@RequestMapping("/mini/vip/hotel/finance")
public class FinanceMiniVipHotelController {

    @Autowired
    private HotelWithdrawalOrderService hotelWithdrawalOrderService;

    @NeedToken
    @ApiOperation(value = "申请提现", notes = "成功返回true,失败抛出错误信息")
    @PostMapping("/withdrawal")
    public AjaxResponseBody<Boolean> withdrawal(@Validated FinanceWithdrawalParam financeWithdrawalParam) {
        AccountInfo loginUser = AccountUtils.getLoginUser();
        List<Integer> typeLists = Lists.newArrayList(1, 5);
        Arguments.isFalse(typeLists.contains(loginUser.getType()), "您无权调用");
        financeWithdrawalParam.setType(HotelWithdrawalOrder.OrderType.MINI_VIP.value());
        hotelWithdrawalOrderService.miniVipHotelWithdrawal(loginUser, financeWithdrawalParam);
        return AjaxResponseBody.success(true);
    }

    @NeedToken
    @ApiOperation(value = "提现订单查询", notes = "提现订单查询", response = HotelWithdrawalOrderResult.class)
    @PostMapping("/list")
    public AjaxResponseBody<PageResult> list(@Validated WithdrawalOrderParam param) {
        param.setOrderType(HotelWithdrawalOrder.OrderType.MINI_VIP.value());
        PageResult<HotelWithdrawalOrderResult> pageResult = hotelWithdrawalOrderService.myMiniVipHotelList(AccountUtils.getLoginUser(), param);
        return AjaxResponseBody.success(pageResult);
    }

}
